﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using ZR.Admin.WebApi.Extensions;
using ZR.Model.mes.md;
using ZR.Service.mes.md;
using ZR.Service.mes.md.IService;
using ZR.Service.MES.md;

namespace ZR.Admin.WebApi.Controllers.mes.md
{

    [Route("mes/md/workstation")]
    public class MdWorkstationController : BaseController
    {

        IMdWorkstationService workstationService;
        public MdWorkstationController(IMdWorkstationService workstationService)
        {
            this.workstationService = workstationService;
        }

        [HttpGet("list")]
        public IActionResult List(int pageNum, int pageSize, string StationCode = "", string StationName = "")
        {

            (int, List<MdWorkstation>) data = workstationService.GetAll(StationCode, StationName, pageNum, pageSize);

            return ToResponse(new ApiResult(200, "success", data));
        }



        [HttpPost("addWorkstation")]
        public IActionResult AddWorkstation([FromBody] MdWorkstation workshop)
        {
            if (workshop != null)
                workshop.ToCreate(HttpContext);
            int result = workstationService.AddWorkshop(workshop);
            return SUCCESS(result);
        }


        [HttpPost("updateWorkstation")]
        public IActionResult UpdateWorkshop([FromBody] MdWorkstation workshop)
        {
            if (workshop != null)
                workshop.ToUpdate(HttpContext);
            int result = workstationService.UpdateWorkshop(workshop);
            return SUCCESS(result);
        }


        [HttpPost("delWorkstation")]
        public IActionResult DelWorkstation([FromBody] List<int> ids)
        {
            if (ids != null)
            {
                int result = workstationService.deleteWorkshop(ids.ToArray());
                return ToResponse(result);
            }
            return null;
        }
      

        [HttpGet("getworkLineList")]
        public IActionResult GetworkLineList()
        {
            List<MdWorkline> MdWorkshopList = workstationService.GetworkLineList();
            return SUCCESS(MdWorkshopList);
        }

    }
}
